<!--
 * @Author: HeAo
 * @Date: 2021-10-12 11:10:34
 * @LastEditTime: 2021-10-12 11:36:42
 * @LastEditors: HeAo
 * @Description: 
 * @FilePath: \web2103-2105\web2105\3-2-Vue\day04\6-自定义指令.html
 * 别乱动！
-->
<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>Document</title>
  <script src="../js/vue.js"></script>
</head>

<body>
  <div id="app">
    <!-- <div v-mymodel="data1">指令测试dom</div> -->
    <input type="text" v-mymodel="data1">
    {{data1}} <br>
    <input type="text" v-mymodel="data2">
    {{data2}}
  </div>
  <script>
    // 1.声明指令对象
    let directive1 = {
      bind(el, binding, vnode, oldVnode) {
        console.log('bind', el, binding, vnode, oldVnode);
      },
      inserted(el, binding, vnode, oldVnode) {
        console.log('inserted', el, binding, vnode, oldVnode);
      },
      update(el, binding, vnode, oldVnode) {
        console.log('update', el, binding, vnode, oldVnode);
      },
      componentUpdated(el, binding, vnode, oldVnode) {
        console.log('componentUpdated', el, binding, vnode, oldVnode);
      },
      unbind(el, binding, vnode, oldVnode) {
        console.log('unbind', el, binding, vnode, oldVnode);
      },
    }

    let directive2 = {
      bind(el, binding, vnode, oldVnode) {
        console.log('bind', el, binding, vnode, oldVnode);
        // 双向数据绑定线路一，将数据模型中的初始值设置到视图中
        el.value = binding.value
        // 双向数据绑定线路二，将视图中变化的数据，动态设置到数据模型中
        el.oninput = (event) => {
          vnode.context.$root[binding.expression] = event.target.value
        }
      }
    }

    let vm = new Vue({
      el: '#app',
      data: {
        data1: 'vue根实例数据',
        data2: 'vue实例数据2'
      },
      methods: {},
      directives: {
        mydir: directive1,
        mymodel: directive2
      }
    })
  </script>
</body>

</html>